import { _decorator, Component, Node, Prefab, RigidBody, BoxCharacterController } from 'cc';

import { poolManager } from '../../../../Framework/Scripts/Managers/poolManager';
import { OBJ_TYPE } from '../../constant';
import { GameApp } from '../../GameApp';
import { enemyBase } from '../enemyBase';
import { FireBall } from '../enemySkill/fireBall';



/** 
  周无邪出品
  本源码用于学习研究使用。
  作者联系方式：tuya7078（微信）。
 */


const { ccclass, property } = _decorator;

@ccclass('catapult')
export class catapult extends enemyBase {

    @property(Prefab)
    public pfWeapon: Prefab = null!;//武器预制体
    @property(Node)
    public ndRightHand: Node = null!;//右手节点

    private weaponNode: Node = null

    private isA:boolean=false


    private atime:number=3
    private nowTime:number=0

    onLoad() {

            super.onLoad()
            this.weaponNode = this.ndRightHand.getChildByName("catapultBoom")
            
     //   this.weaponNode = poolManager.instance.getNode(this.pfWeapon, this.ndRightHand)


    }




    start() {



    }
    attack() {
        if(this.isA){
            return
        }
        this.isA=true
        super.attack()
       // this.NavTs.StopNav()
        this.node.lookAt(this.attackTarget.getWorldPosition())
        this.weaponNode.active = true
        this.enemyModel.playAni(this.attackAni1, false,()=>{
          //  this.NavTs.StopNav()
            this.enemyModel.playAni(this.walkAni, true)
        })



    }

    protected  friendly_pursuit() {
        this.isA=false
        this.weaponNode.active = true
       super.friendly_pursuit()
    }
    protected pursuit_building() {
        this.isA=false
        this.weaponNode.active = true
        super.pursuit_building()

    }

    protected enemy_pursuit() {
        this.isA=false
        this.weaponNode.active = true
        super.enemy_pursuit()
    }
    public attickCallback() {

     //   console.log("投石器");

        this.weaponNode.active = false

        const n: Node = poolManager.instance.getNode(this.pfWeapon, GameApp.Instance.skillRoot)
        n.setWorldPosition(this.ndRightHand.worldPosition)
        n.setScale(1.2,1.2,1.2)



        let ts: FireBall = n.getComponent(FireBall)




        if (ts) {


            ts.init(15, this.ndRightHand.getWorldPosition(), this.attackTarget.getWorldPosition(),3,this.node)


        }
    }//攻击回调
    update(dt: number) {
        if(this.isA){
            this.nowTime+=dt
            if(this.nowTime>=this.atime){
                this.nowTime=0
                this.isA=false
            }
        }
        super.update(dt)
    }
}


